package org.daochong.spring.util;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;

import org.daochong.lang.Resource;

public class ResourceAdaper implements org.springframework.core.io.Resource {
	private Resource resource;

	public ResourceAdaper(Resource resource) {
		this.resource = resource;
	}

	
	public InputStream getInputStream() throws IOException {
		return resource.getInputStream();
	}

	
	public long contentLength() throws IOException {
		return resource.contentLength();
	}

	
	public org.springframework.core.io.Resource createRelative(String sring) throws IOException {
		return this;
	}

	
	public boolean exists() {
		return true;
	}

	
	public String getDescription() {
		return this.resource.getSource();
	}

	
	public File getFile() throws IOException {
		return this.resource.getSourceFile();
	}

	
	public String getFilename() {
		return this.resource.getFileName();
	}

	
	public URI getURI() throws IOException {
		return this.resource.getSourceFile().toURI();
	}

	
	public URL getURL() throws IOException {
		return this.resource.getSourceFile().toURI().toURL();
	}

	
	public boolean isOpen() {
		return false;
	}

	
	public boolean isReadable() {
		return true;
	}

	
	public long lastModified() throws IOException {
		return this.resource.lastModified();
	}

	
	public String toString() {
		return "file [" + this.resource.getSource() + "]";
	}

}
